home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 702 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  987 b 

  1. Path: news.tiac.net!smayo
  2. From: smayo@tiac.net (Scott Mayo)
  3. Newsgroups: comp.std.c
  4. Subject: Is it legal to add 0 to NULL? What about NULL < NULL?
  5. Date: Sat, 06 Apr 1996 10:02:08 -0500
  6. Organization: The Internet Access Company
  7. Message-ID: <ff1d.smail.smayo@tiac.net>
  8. NNTP-Posting-Host: sunspot.tiac.net
  9.  
  10. I ask because a standard trick for walking an array A of size S is:
  11.  
  12. Thing *a = A;
  13. Thing *fence = a + S;
  14. for (; a < fence; ++a)
  15.     /* use a */;
  16.  
  17. but in my case, if S happens to be 0, a will start out NULL. This makes we
  18. worry about both the value of fence, and, if that works, the behaviour
  19. of (a < fence), which I hope is (NULL < NULL), which I hope the standard
  20. blesses as reliably false, but I have this feeling that it won't.
  21.  
  22. I know I can use int i; for (i = 0; i < S; ++i) but I was
  23. hoping to avoid the extra math at array dereference time. I know
  24. I can preface the whole thing with if (a != NULL) but the fun of
  25. a standard is knowing what you can get away with. :)
  26.  
  27. Comments?
  28.